﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using HFK.DxFluentUITest.Dummy;
using HFK.DxFluentUITest.Dummy.DataObjects;
using HFK.DxFluentUI.Utility;
using HFK.DxFluentUI.VerticalGrid;
using MbUnit.Framework;
using DevExpress.XtraVerticalGrid;

namespace HFK.DxFluentUITest.VerticalGridControl
{
  [TestFixture]
  public class VerticalGridControlDatabindingTestFixture
  {
    [Test]
    public void TestDataBinding()
    {
      VerticalGridDataBinding vgrid = new VerticalGridDataBinding();
      VGridControl verticalGrid = vgrid.Get;

      TypedList<SimpleClass> data = new TypedList<SimpleClass>();
      data.Add(new SimpleClass() { IntValue = 1, ShcData = new SingleHopClass() { DhcProperty = new DualHopClass() { ThcProperty = new TripleHopClass() { StringProperty = "S1" } } } });
      data.Add(new SimpleClass() { IntValue = 2, ShcData = new SingleHopClass() { DhcProperty = new DualHopClass() { ThcProperty = new TripleHopClass() { StringProperty = "S2" } } } });

      Form form = new Form();
      form.Controls.Add(verticalGrid);

      verticalGrid.DataSource = vgrid.Data(data);
      verticalGrid.Update();

      form.Show();

      Thread.Sleep(2000);

      Assert.AreEqual("1", verticalGrid.GetCellDisplayText(verticalGrid.Rows[0], 0));
      Assert.AreEqual("2", verticalGrid.GetCellDisplayText(verticalGrid.Rows[0], 1));
      Assert.AreEqual("S1", verticalGrid.GetCellDisplayText(verticalGrid.Rows[1], 0));
      Assert.AreEqual("S2", verticalGrid.GetCellDisplayText(verticalGrid.Rows[1], 1));

      form.Close();
    }
  }
}
